﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Todo.Models;

namespace Todo.Services
{
    public class DataService : IDataService
    {
        List<TodoItem> _items = new List<TodoItem>() {
            new TodoItem()
            {
                Id = 1,
                Title = "Test 1"
            },
            new TodoItem()
            {
                Id = 2,
                Title = "Test 2"
            },
            new TodoItem()
            {
                  Id = 3,
                Title = "Test 3"
            }
        };

        public Task AddItemAsync(TodoItem item)
        {
            return Task.Run(() => _items.Add(item));
        }

        public Task<TodoItem> GetItemAsync(int id)
        {
            return Task.Run(() => _items.First(x => x.Id == id));
        }

        public Task<IEnumerable<TodoItem>> GetItemsAsync()
        {
            return Task.Run<IEnumerable<TodoItem>>(() => _items);
        }

        public Task UpdateItemAsync(TodoItem item)
        {
            return Task.Run(() => { });
        }
    }
}
